﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Labb2
{
    class SplitterSystem
    {
        private Texture2D background;
        private Texture2D dogeTexture;
        private Vector2 m_startingPosition;

        SplitterParticle[] splitterArray;
        Camera m_camera;

        public SplitterSystem(Camera camera, Vector2 startingPosition) 
        {
            m_camera = camera;
            m_startingPosition = startingPosition;
            splitterArray = new SplitterParticle[100]; 
        }

        internal void Update(GameTime gameTime) 
        {
            foreach (SplitterParticle doge in splitterArray)
            {
                doge.Update(gameTime);
            }
        }
        
        internal void Draw(SpriteBatch spritebatch) 
        {
            spritebatch.Draw(background, new Rectangle(0, 0, (int)m_camera.Resolution.X, (int)m_camera.Resolution.Y), Color.White);
            foreach(SplitterParticle doge in splitterArray)
            {
                doge.Draw(spritebatch);
            }
        }

        internal void LoadContent(ContentManager contManager) 
        {
            background = contManager.Load<Texture2D>("dogeBackground");
            dogeTexture = contManager.Load<Texture2D>("doge");

            for (int i = 0; i < 100; i++ ) 
            {
                SplitterParticle doge = new SplitterParticle(m_startingPosition, i, dogeTexture, m_camera);
                splitterArray[i] = doge;
            }
        }

        internal void ResetArray()
        {
            Array.Clear(splitterArray,0,100);
        }
    }
}
